//*去掉空格*/
String.prototype.Trim = function() {
	var m = this.match(/^\s*(\S+(\s+\S+)*)\s*$/);
	return (m == null) ? "" : m[1];
}
//*用户名判断 * 用户名由4到20位字母、数字组成或2-8个中文 如果returnErrorMsg为true则会返回错误类行对应的数字* */
String.prototype.isUserName = function() {
	var str=this.Trim();
	var totalNum=0;	
	var c="";
	for(var i=0;c=str.charAt(i);i++){
		if(/[\w\d]/.test(c)){
			totalNum=totalNum+1;
		}else if(/[\u4E00-\u9FA5]/.test(c)){
			totalNum=totalNum+2;
		}else{
			return false;
		}
	}
	if(totalNum>=4&&totalNum<=20){
		return true;
	}
	//return (/^([\w\d]{4,20}|[\u4E00-\u9FA5\w\d]{2,10})$/.test(this.Trim()));
}

//*密码判断 * 密码由6到16位字母和数字组成* */
String.prototype.isPassword = function() {
	return (/^[a-zA-Z0-9]{6,16}$/.test(this.Trim()));
}
//*密码判断 * 密码由6到12位字母和数字组成* */
String.prototype.isEmpt = function() {
	if(this.Trim().length<1) 
		{return true ;}
	else 
		{return false ;}
}
//判断是否输入了特殊字符
String.prototype.isCheckQuote=function(){
   var items = new Array("~", "`", "!", "@", "#", "$", "%", "^", "&", "*", "{", "}", "[", "]", "(", ")"," ");
    items.push(":", ";", "'", "|", "\\", "<", ">", "?", "/", "<<", ">>", "||", "//");
    items.push("admin", "administrators", "administrator", "管理员", "系统管理员");
    items.push("select", "delete", "update", "insert", "create", "drop", "alter", "trancate");
    var str = this.toLowerCase();
    for (var i = 0; i < items.length; i++) {
        if (str.indexOf(items[i]) >= 0) {
            return true;
        }
    }
    return false;
}
//*判断是否为邮箱*/
String.prototype.isEmailAddress = function() {
	return (/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/g.test(this.Trim()));	        
}
//*判断是否为手机号码*/
String.prototype.isMobile = function() {
	return (/^(?:13\d|15\d|18\d|14\d|17\d)-?\d{5}(\d{3}|\*{3})$/.test(this.Trim()));
}
//*判断是否为数字组成的字符串*/
String.prototype.isNumber = function() {
	return (/^[0-9]*$/.test(this.Trim()));
}
//*判断是否为中文*/
String.prototype.isZhongWen = function() {
	return (/^[\u4e00-\u9fa5]{0,}$/.test(this.Trim()));
}
//*判断是否为邮编*/
String.prototype.isPostcode = function() {
	return (/^[0-9]{6}$/.test(this.Trim()));
}
//*判断是否为身份证*/
String.prototype.isID = function() {
   //15位数身份证正则表达式
    var arg1 = /^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$/;
    //18位数身份证正则表达式
    var arg2 = /^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])((\d{4})|\d{3}[A-Z])$/;
    if (this.match(arg1) == null && this.match(arg2) == null) {
        return false;
    }else {
        return true;
    };
}
//*判断是否为两位小数的正实数*/
String.prototype.isNumPoint = function() {
	return (/^[0-9]+(.[0-9]{0,2})$/.test(this.Trim()));
}
//*判断是否为URL地址*/
String.prototype.isURL = function() {
	return (/(http[s]?|ftp):\/\/[^\/\.]+?\..+\w$/i.test(this.Trim()));
}
//*判断是否为正整数*/
String.prototype.isPlus = function() {
	return (/^[0-9]+$/.test(this.Trim()));
}
//*判断字符由字母和数字组成*/
String.prototype.isCharAndNum = function() {
	return (/^[A-Za-z0-9]+$/.test(this.Trim()));
}
//*判断字符由字母组成*/
String.prototype.isCharStr = function() {
	return (/^([a-zA-z]+)$/.test(this.Trim()));

}
//*判断折扣*//
String.prototype.isDiscount = function() {
	return (/^[0]+\.?[0-9]+$/.test(this.Trim()));
}

String.prototype.isPlus = function() {
	return (/^[0-9]+$/.test(this.Trim()));
}

String.prototype.isPriceNumber = function() {
	return (/^\d+\.\d+$/.test(this.Trim()) || /^\d+$/.test(this.Trim()));
}
//*只能输入数字
function onlyNum() 
{ 
if(!(event.keyCode==46)&&!(event.keyCode==8)&&!(event.keyCode==37)&&!(event.keyCode==39)) 
if(!((event.keyCode>=48&&event.keyCode<=57)||(event.keyCode>=96&&event.keyCode<=105))) 
event.returnValue=false; 
}
//*只允许输入数字和小数点
function onlydouble(obj){ 
   obj.value = obj.value.replace(/[^\d.]/g,"");  //清除“数字”和“.”以外的字符 
   obj.value = obj.value.replace(/^\./g,"");  //验证第一个字符是数字而不是. 
   obj.value = obj.value.replace(/\.{2,}/g,"."); //只保留第一个. 清除多余的. 
   obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$","."); 
}
//*只能输入数字和字母
function onlyNumString(hehe)
{
  var pattern = /[^0-9a-zA-Z]/g;
   if(pattern.test(hehe.value))
  {
    hehe.value = hehe.value.replace(pattern,"");
  }
}
//只允许输入数字和中划线
function onlyNumLine(hehe)
{
  var pattern = /[^0-9-]/g;
   if(pattern.test(hehe.value))
  {
    hehe.value = hehe.value.replace(pattern,"");
  }
}
//只允许输入数字和"/"
function onlyNumLine2(hehe)
{
  var pattern = /[^0-9/]/g;
   if(pattern.test(hehe.value))
  {
    hehe.value = hehe.value.replace(pattern,"");
  }
}
//只允许输入数字和"/"和","
function onlyNumLine3(hehe)
{
  var pattern = /[^0-9-,]/g;
   if(pattern.test(hehe.value))
  {
    hehe.value = hehe.value.replace(pattern,"");
  }
}
//**比较两个日期的大小 时间格式 2009-01-01**/
function compareDateStr(dateStr1, dateStr2) {
	dateStr1 = convDate(dateStr1, "-");
	dateStr2 = convDate(dateStr2, "-");
	if (dateStr1 > dateStr2) {
		return 1;
	}else if(dateStr1 == dateStr2){
		return 0;
	}else{
		return -1;
	}
}
function convDate(sDate, sSep) {
    var tem = sDate.replace(sSep,"");
    return tem.replace(sSep,"");
}
//去除两头空格
function LRTrim(obj) {
	obj.value = obj.value.replace(/\s+$|^\s+/g,"");
}

// 去左空格
function LTrim(obj) {
	obj.value = obj.value.replace(/^\s+/,"");
}

// 去右空格
function RTrim(obj) {
	obj.value = obj.value.replace(/\s+$/,"");
} 
//过滤HTML代码
function RemoveHTML(obj){
		obj.value = obj.value.replace(/<\/?[^>]*>/g,''); //去除HTML tag
		//obj.value = obj.value.replace(/\s+$|^\s+/g,""); //去除两头空格
		//obj.value = obj.value.replace(/\n[\s| | ]*\r/g,'\n'); //去除多余空行
}

function checkPersonName(str){
    var str=str.substr(0,1); //截取用户提交的用户名的前两字节，也就是姓。 
    var surname="赵钱孙李周吴郑王冯陈褚卫蒋沈韩杨朱秦尤许何吕施张孔曹严华金魏陶姜戚谢邹喻柏水窦章云苏潘葛奚范彭郎鲁韦昌马苗凤花方俞任袁柳酆鲍史唐费廉岑薛雷贺倪汤滕殷罗毕郝邬安常乐于时傅皮卞齐康伍余元卜顾孟平黄和穆萧尹姚邵湛汪祁毛禹狄米贝明臧计伏成戴谈宋茅庞熊纪舒屈项祝董梁杜阮蓝闵席季麻强贾路娄危江童颜郭梅盛林刁锺徐邱骆高夏蔡田樊胡凌霍虞万支柯昝管卢莫经房裘缪干解应宗丁宣贲邓郁单杭洪包诸左石崔吉钮龚程嵇邢滑裴陆荣翁荀羊於惠甄麴家封芮羿储靳汲邴糜松井段富巫乌焦巴弓牧隗山谷车侯宓蓬全郗班仰秋仲伊宫宁仇栾暴甘钭历戎祖武符刘景詹束龙叶幸司韶郜黎蓟溥印宿白怀蒲邰从鄂索咸籍赖卓蔺屠蒙池乔阳郁胥能苍双闻莘党翟谭贡劳逄姬申扶堵冉宰郦雍却璩桑桂濮牛寿通边扈燕冀僪浦尚农温别庄晏柴瞿阎充慕连茹习宦艾鱼容向古易慎戈廖庾终暨居衡步都耿满弘匡国文寇广禄阙东欧殳沃利蔚越夔隆师巩厍聂晁勾敖融冷訾辛阚那简饶空曾毋沙乜养鞠须丰巢关蒯相查后荆红游竺权逮盍益桓公岳"+
                 "蹇称诺来多繁戊朴回毓税荤靖绪愈硕牢买但巧枚撒泰秘亥绍以壬森斋释奕姒朋求羽用占真穰翦闾漆贵代贯旁崇栋告休褒谏锐皋闳在歧禾示是委钊频嬴呼大威昂律冒保系抄定化莱校么抗祢綦悟宏功庚务敏捷拱兆丑丙畅苟随类卯俟友答乙允甲留尾佼玄乘裔延植环矫赛昔侍度旷遇偶前由咎塞敛受泷袭衅叔圣御夫仆镇藩邸府掌首员焉戏可智尔凭悉进笃厚仁业肇资合仍九衷哀刑俎仵圭夷徭蛮汗孛乾帖罕洛淦洋邶郸郯邗邛剑虢隋蒿茆菅树桐锁钟机盘铎斛玉线针庹绳磨蒉瓮弭刀疏牵浑恽势世同蚁止睢冼种涂肖己泣卷脱谬赧浮顿次错念夙斯完丹表聊源姓吾寻展出不户闭才无书学愚本雪霜烟寒少字桥板斐独千诗嘉扬善让尧依犹介承市所苑杞剧第零谌招续达忻六鄞战迟宛励粘萨邝覃辜初楼城区局台原考纳泉老德卑过麦曲竹百福言佟爱年哈墨赏伯商左丘梁丘琴后况亢微生羊舌海归呼延南门东郭百里钦鄢汝法闫楚晋谷梁夹谷公西巫马端木颛孙子车督仉司寇鲜于锺离盖逯库郏逢阴薄厉稽闾丘公良段干开光瑞泥运伟铁迮" ;
    r=surname.search(str);// 查找字符串。
    if(r==-1)
    	return false
    else 
    	return true
}

String.prototype.isPersonName = function() {

	return checkPersonName(this);
}
String.prototype.exactLenght=function() {
    var len = 0;
    for (var i = 0; i < this.length; i++) {
        if (this.charCodeAt(i) > 255) len += 2; else len ++;
    }
    return len;
}